package com.cnunicom.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.cnunicom.domain.Product;
import com.cnunicom.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: dingziyuan
 * @Date: 2020/4/4/004 21:14
 * @Description: *
 */
@RestController
@RequestMapping("/product")
@Slf4j
public class ProductController {

    @Resource
    private ProductService productService;

    @RequestMapping("/info/{pid}")
    public Product productInfo(@PathVariable Integer pid) {
        log.info("接下来要进行商品信息查询，id={}",pid);
        Product product = productService.findByPid(pid);
        log.info("商品信息查询成功，内容为{}", JSON.toJSONString(product,SerializerFeature.PrettyFormat));
        return product;
    }
}
